from sqlalchemy import or_

from databases.models import session, Group, User

# group = Group(name='销售')
# session.add(group)
# session.commit()
# session.close()

group = session.query(Group).filter_by(name='销售').one()

# user1 = User(username='小倩', password='password', real_name='叶倩文', email='qian@gmail.com', group=group)
# user2 = User(username='团团', password='password', real_name='李香团', email='tuan@gmail.com', group=group)
# user3 = User(username='开心果', password='password', real_name='王毅光', email='光@gmail.com', group=group)
#
# session.add_all([user1, user2, user3])

# print(group.users)
# for user in group.user:
#     print(user.username)


# users = session.query(User).filter(or_(Group.name == '销售', Group.name == '财务')).all()
users = session.query(User).filter(Group.name == '销售').all()
# users = session.query(User).filter_by(group=group).all()
for user in users:
    print(user.username)
# print(user.group)
# print(user.group.name)











session.commit()
session.close()
